home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byt0187b.arc
/
SAVERGN.ASM
< prev
next >
Wrap
Assembly Source File
|
1986-08-12
|
10KB
|
483 lines
; SaveRgn.ASM 20 July '86 h. katz
; Abstracted from < RgnMaker.ASM >
; This module handles the code for creating a Macintosh resource from
; the region in the Work Area which was produced by the contouring
; algorithm in < Traverse.ASM >.
; It uses a Dialog Box to get the user-input parameters for defining
; the Resource Type, ID, and Name, reloading these DITLs from memory if a
; resource has already been written to disk this session.
; The program uses the _Pack3 SFPutFile routine to get the name of
; the file the user wishes to add the resource to.
INCLUDE MacTraps.D
XDEF Save_To_File, Have_Prior_DITLs ; defined here but
XDEF ItemHit, PutFile_Posit ; used in < RgnMaker.ASM >
XREF Save_Image, Restore_Image, Stop_Alert, RgnHandle, UnHiLite
SFPutFile equ 1 ; selector for _Pack3
PutFile_ID equ -3999
Replace_DITL equ -3996
ioNamePtr equ 18
ioVRefNum equ 22
StringToNum equ 1
Res_DLOG_ID equ 100
Cancel_Button equ 2
Res_Type_DITL_Num equ 7
Res_ID_DITL_Num equ 8
Res_Name_DITL_Num equ 9
Save_To_File
_InitCursor
move #Res_DLOG_ID, d3 ; ResID of upcoming Dialog
move.l #'DLOG', a3
BSR Save_Image ; save Bits to be hidden by the DLOG
bsr Open_Res_DLOG
tst.b Have_Prior_DITLs(a5) ; did we do this before ?
BEQ.s Get_User_Choice ; no - first time
BSR Reload_Old_DITLs
Get_User_Choice
st Have_Prior_DITLs(a5)
BSR Modal_DLOG ; get kbd-input for Resource Type,
tst d4 ; ID, and Name
bmi.s Save_To_File ; input param error - try again
pea Res_DLOG_Storage ; all done - dispose of Dialog
_CloseDialog ; (and erase from screen)
BSR Restore_Image ; redraw what was underneath
cmp #Cancel_Button, d4
beq UnHiLite ; User selected 'Cancel'
BSR Put_To_File ; everything OK - SFPutFile
BRA UnHiLite
Reload_Old_DITLs ; restore Dialog Items saved in prior session
move #Res_Type_DITL_Num, D4
BSR Get_Item_Handle
move.l ItemHandle, -(sp)
pea Resource_Type_STR
_SetIText
move #Res_Id_DITL_Num, D4
BSR Get_Item_Handle
move.l ItemHandle, -(sp)
pea Resource_ID_Str
_SetIText
move #Res_Name_DITL_Num, D4
BSR Get_Item_Handle
move.l ItemHandle, -(sp)
pea Resource_Name
_SetIText
RTS
Get_Item_Handle
pea Res_DLOG_Storage ; DLOG Ptr
move d4, -(sp) ; Item Number
pea ItemType ; not used
pea ItemHandle ; passed to following ROM call
pea ItemBox ; not used
_GetDItem
RTS
Put_To_File
; The user has successfully specified the Resource TYPE and ID.
; Append it to an existing file, or create a new one if necessary
; The 1st piece of code replaces the message 'Replace Existing ...'
; with an 'Are You Sure ?', which makes more sense in the
; circumstances, as we're not replacing anything.
clr.l -(sp)
move.l #'DITL', -(sp)
move #Replace_DITL, -(sp) ; 'Replace Existing File' DITL
_GetResource
move.l (sp)+, a0 ; get the Handle
cmpa.l #0, a0
BEQ.s @SFPutFile ; couldn't get DITL - forget it
move.l (a0), a0 ; get the Ptr to DITL data
move -2(a0), d0 ; Block size ( in Block Header )
@Search_Length_Byte
cmp.b #$17, (a0)+ ; look for matching String Length
dBEQ d0, @Search_Length_Byte
cmp #-1, d0
BEQ.s @SFPutFile ; fell thru without finding match
cmp.b #'R', (a0) ; check for 'R' of 'Replace'
BNE.s @SFPutFile ; forget it
lea 'Are You Sure ? ', a1
move.b (a1)+, d1 ; save Length Byte
ext.w d1 ; get rid of what was in hi nibble
sub #1, d1
@Replace_Str
move.b (a1)+, (a0)+
DBRA d1, @Replace_Str
@SFPutFile
move #PutFile_ID, d3 ; ResID of upcoming Dialog
move.l #'DLOG', a3
BSR Save_Image ; save Bits to be hidden by the DLOG
move.l PutFile_Posit, -(sp) ; Global TopLeft of Dialog
pea 'Append Resource to File'
pea 'Resources'
move.l #0, -(sp)
pea SFReply
move #SFPutFile, -(sp)
_Pack3
BSR Restore_Image ; redraw what was underneath
move.b good, d0
tst.b d0 ; Did user 'Cancel' out ?
beq @Rts ; yes
BSR Create_ioPB
_GetVol ; get Info on the Default Volume
move iovRefNum(a0), Default_Vol(a5) ; save the RefNum
move iovRefNum(a0), d0 ; to restore it later
cmp vRefNum, d0 ; is file we want to add resource to
; on the Default Volume ?
beq.s @1 ; yes
clr.l ioNamePtr(a0) ; no
move vRefNum, iovRefNum(a0)
_SetVol ; make it the Default Volume
@1 add.l d4, sp ; clear the ioPB off the stack
clr -(sp)
_CurResFile
move (sp)+, CurResFile(a5) ; save the refNum for later
clr -(sp)
pea fName ; File Name that user entered
_OpenResFile ; try to open it
move (sp)+, d3 ; save the refNum for later
clr -(sp)
_ResError ; see if we could open it
move (sp)+, d0
tst d0
beq.s @2 ; we could
pea fName ; we couldn't
_CreateResFile ; so try to create it
clr -(sp)
_ResError
move (sp)+, d0
tst d0
bne @9 ; we couldn't create it
clr -(sp) ; we created it
pea fName ; now try to open it
_OpenResFile
move (sp)+, d3 ; save the refNum for later
clr -(sp)
_ResError ; check if we were able to open
move (sp)+, d0
tst d0
beq.s @2 ; hunky-dory
move #105, d3 ; 'Can't add to file' message
BSR Stop_Alert
bra @9
@2 move d3, -(sp) ; we were able to open the specified file
_UseResFile ; make it the current Resource File
clr.l -(sp) ; check to see if we have a duplicate
move.l Resource_Type, -(sp) ; push Type (w/out Length Byte)
move.l Resource_ID, d0 ; push low word of ID
move d0, -(sp)
_GetResource
move.l (sp)+, d0 ; check the returned Handle
beq.s @3 ; NIL Handle = OK, no Duplicate
clr -(sp) ; space for INT result
move.l d0, -(sp) ; push handle again
_HomeResFile
move (sp)+, d0 ; get refNum
cmp d0, d3 ; is it in the currResFile we're using ?
bne.s @3 ; no = OK
move #104, d3 ; alertID for 'Duplicate Resource'
BSR Stop_Alert
bra @5 ; detach the resource
@3 move.l RgnHandle(a5), -(sp) ; point to the Region ( theData )
move.l Resource_Type, -(sp)
move.l Resource_ID, d0 ; ID saved initially as a LONG
move d0, -(sp) ; push low word only
pea Resource_Name
_AddResource
clr -(sp) ; check for errors
_ResError
move (sp)+, d0 ; get the result
beq.s @4 ; no error
move #106, d3 ; 'Can't Add to File' AlertID
BSR Stop_Alert
bra @9
@4 move.l RgnHandle(a5), -(sp)
_WriteResource
clr -(sp) ; check for errors
_ResError
move (sp)+, d0
beq.s @5 ; no error
move #105, d3 ; 'Can't Add to File' AlertID
BSR Stop_Alert
bra @9
@5 move.l RgnHandle(a5), -(sp) ; just a region again
_DetachResource ; (no longer a resource)
@9 BSR Create_ioPB ; restore original Default Volume
move Default_Vol(a5), iovRefNum(a0)
_SetVol
add.l d4, sp ; clear ioPB off the stack
move CurResFile(a5), -(sp)
_UseResFile ; restore prior Resource File
@Rts RTS
Create_ioPB
move.l (sp)+, a1
move.l #100, d0 ; set up a temp ioPB on the stack
move.l d0, d4 ; save for cleanup
asr #2, d0 ; 100 Bytes -> 25 Longs (more than we really
sub #1, d0 ; need, actually)
@Push
move.l #0, -(sp)
dbra d0, @Push
move.l sp, a0 ; sp = addr of ioParamBlock
jmp (a1)
Open_Res_DLOG
clr.l -(sp) ; space for funct result
move #Res_DLOG_ID, -(sp)
pea Res_DLOG_Storage
move.l #-1, -(sp) ; in front of everything
_GetNewDialog
move.l (sp)+, d0
RTS
Modal_DLOG
clr.l -(sp) ; no filterProc
pea ItemHit
_ModalDialog
move ItemHit, d4
cmp #1, d4 ; is it 'OK' ?
beq.s @OK_Button ; yes - save DITL EditText Items
cmp #2, d4 ; is it 'Cancel' ?
BNE Modal_DLOG ; not yet - stick around
RTS
@OK_Button
move #Res_Type_DITL_Num, d3
bsr Save_Text
lea Resource_Type_Str, a0
move.b (a0)+, d0 ; also save the Resource Type
lea Resource_Type, a1 ; w/o a Length Byte for _AddResource
move.b (a0)+, (a1)+
move.b (a0)+, (a1)+
move.b (a0)+, (a1)+
move.b (a0)+, (a1)+
move #Res_ID_DITL_Num, d3 ; save the ID Number
bsr Save_Text ; ( both as Str and INT )
move #Res_Name_DITL_Num, d3 ; save the Resource Name
bsr Save_Text
lea Resource_Type_STR, a0
move.b (a0), d0 ; get the Length Byte
cmp #4, d0
BEQ.s @Check_ID ; length 4 = OK
move #103, d3 ; 'ResType must be 4 Chars'
BRA Param_Err
@Check_ID
move #106, d3 ; assume '0 - 32767' error
move.l Resource_ID, d0 ; get the INT form of the ResID
cmp.l #32767, d0
bls @1 ; OK so far
bra Param_Err ; whoops - larger than 32767
@1 lea Resource_ID_Str, a0
move.b (a0)+, d0 ; String Length
cmp.b #0, d0 ; length = 0 ?
bne.s @2 ; no
BRA Param_Err ; no ID entered
@2 move #107, d3 ; assume 'Resource ID must be 0 ... 9'
; error
sub.b #1, d0 ; check that each char is digit
ext.w d0
@Loop cmp.b #'0', (a0)
bpl.s @3 ; OK so far
BRA Param_Err
@3 cmp.b #'9', (a0)+
dbHI d0, @Loop
cmp #-1, d0 ; did we exit on an error ?
bne Param_Err ; yes
move #0, d4 ; no error flag
RTS
Param_Err ; ResID of Error String in d3
move #-1, d4 ; errFlag
pea Res_DLOG_Storage
_CloseDialog
BSR Restore_Image
BSR Stop_Alert
RTS
Save_Text
pea Res_DLOG_Storage
move d3, -(sp) ; Item Number
pea ItemType
pea ItemHandle
pea ItemBox ; get the Handle, given
_GetDItem ; the Item Number in D3
move.l ItemHandle, -(sp)
cmp #Res_Type_DITL_Num, d3
bne.s @1
pea Resource_Type_STR
_GetIText
RTS
@1 cmp #Res_ID_DITL_Num, d3
bne.s @2
pea Resource_ID_Str ; first save the ID as a String
_GetIText
lea Resource_ID_Str, a0 ; then save it as an INTEGER
move #StringToNum, -(sp) ; ( actually a LONG )
_Pack7
lea Resource_ID, a0
move.l d0, (a0)
RTS
@2 pea Resource_Name
_GetIText
RTS
; ---------- CONSTs ( PC-relative ) --------------
Res_DLOG_Storage dcb.b 170, 0
PutFile_Posit dc.l $00340064 ; TopLeft = ( 52, 100 )
SFReply
good: dc.b 0
copy: dc.b 0
fType: dc.l 0
vRefNum: dc.w 0
version: dc.w 0
fName: dcb.b 64, 0
ItemHit dc 0
ItemType dc 0
ItemHandle dc.l 0
ItemBox dcb.l 2, 0
tempString dcb.b 40, 0
Resource_Type_Str dcb.b 10, 0 ; allow for overage
Resource_ID_Str dcb.b 10, 0 ; resID as a String
Resource_Name dcb.b 20, 0
Resource_Type dc.l 0 ; ResType w/out Length Byte
Resource_ID dc.l 0 ; resID as a LONG ( really INT )
; ----------- VARS ( off A5 ) ------------------
Have_Prior_DITLs ds.b 1
Default_Vol ds 1
CurResFile ds 1
END